# Maintainer: Jelle van der Waa <jelle@dwaa.nl>

pkgname=prometheus-blackbox-exporter
pkgver=0.19.0
pkgrel=1
pkgdesc="Allows blackbox probing of endpoints over HTTP, HTTPS, DNS, TCP and ICMP"
arch=('x86_64')
url="https://github.com/prometheus/blackbox_exporter"
license=('Apache')
depends=(glibc)
makedepends=(go git)
source=($pkgname-$pkgver.tar.gz::https://github.com/prometheus/blackbox_exporter/archive/v${pkgver}.tar.gz prometheus-blackbox-exporter.service)
sha512sums=('86b11bc7afa0d8261d0961ca21563047b1ea8bfd1a9d4d034c393a8b098b035147883a44011cdafca8e9795a5e9a043cc15235375990f3424137af63469a8878'
            'b32d7772cbd8a2fc741d827a7f221d1302ab0c5833c095e5b6dc6befa46a1b12c22e91252fd0e4cf07c9c309d6315c6e1d020508a3baaaa891ab9f7f7d690eae')

check() {
  cd blackbox_exporter-$pkgver
  go test ./...
}

build() {
  cd blackbox_exporter-$pkgver
  go build \
    -trimpath \
    -buildmode=pie \
    -mod=readonly \
    -modcacherw \
    -ldflags "-linkmode external -extldflags ${LDFLAGS} \
      -X github.com/prometheus/common/version.Version=$pkgver \
      -X github.com/prometheus/common/version.Revision=$pkgver \
      -X github.com/prometheus/common/version.Branch=tarball \
      -X github.com/prometheus/common/version.BuildUser=someone@builder \
      -X github.com/prometheus/common/version.BuildDate=$(date --date=@"$SOURCE_DATE_EPOCH" +%Y%m%d-%H:%M:%S)" \
    .
}

package() {
  install -Dm644 prometheus-blackbox-exporter.service "$pkgdir"/usr/lib/systemd/system/prometheus-blackbox-exporter.service
  cd blackbox_exporter-$pkgver
  install -Dm755 blackbox_exporter "$pkgdir"/usr/bin/prometheus-blackbox-exporter
}
